
<script>
	var url;
	$(document).ready(function(){
		
		//tambah data
		newData = function (){
			$('#dialog').dialog({
				title: 'Tambah Data Nominasi',
				width: $(window).width() * 0.95,
				height: $(window).height() * 0.95,
				closed: true,
				cache: false,
				href: base_url+'lifting_kkks/add',
				modal: true
			});
			 
			$('#dialog').dialog('open');
			url = base_url+'nominasi/save/add';
		}
		
		editData = function (val,val2,val3){
			$('#dialog').dialog({
				title: 'Detail Data',
				width: 1200,
				height: 500,
				closed: true,
				cache: false,
				href: base_url+'lifting_kkks/edit/'+val+'/'+val2+'/'+val3,
				modal: true,
				buttons:[{
					text:'Batal lifting_kkks',
					iconCls: 'icon-ok',
					handler:function(){
						saveData();
					}
				},{
					text:'Batal',
					iconCls: 'icon-cancel',
					handler:function(){
						$('#dialog').dialog('close');
					}
				}]
			});
			
			$('#dialog').dialog('open');  
			url = base_url+'lifting_kkks/save/edit';
		}
			//end editData
		
		// save data
		saveData = function(){
			$('#form1').form('submit',{
				url: url,
				onSubmit: function(){
					return $(this).form('validate');
				},
				success: function(result){
					//alert(result);
					var result = eval('('+result+')');
					if (result.success){
						$('#dialog').dialog('close');		// close the dialog
						$('#dg').datagrid('reload');		// reload the user data
					} else {
						ShowMessageError(result.msg);
					}
				}
			});
		}
		//end saveData
		
		deleteData = function (id,NAMA_KPS,TAHUN,BULAN,TANGGAL,ID_KPS){
				//var row = $('#dg').datagrid('getSelected');
				//if(row){
					if(confirm("Apakah yakin akan menghapus data?" +'\n' +NAMA_KPS+'\n Tahun : '+TAHUN+' , Bulan : ' +BULAN+', Tanggal : '+TANGGAL)){
						var response = '';
						$.ajax({ type: "GET",
							 url: base_url+'nominasi/delete/' + id + '/' + ID_KPS+ '/' + TAHUN+ '/' + BULAN,
							 async: false,
							 success : function(response){
								var response = eval('('+response+')');
								if (response.success){
									$.messager.show({
										title: 'Success',
										msg: 'Data Berhasil Dihapus'
									});
									// reload and close tab
									$('#dg').datagrid('reload');
								} else {
									$.messager.show({
										title: 'Error',
										msg: response.msg
									});
								}
							 }
						});
					}
				//}
			}
			//end deleteData 	
			
		doSearch = function (){
				$('#dg').datagrid('load',{
					NAMA_KPS: $('#nama').val()
					
				});
			}
	//		
		$(function(){
			$('#dg').datagrid({url:"<?=base_url()?>lifting_kkks/grid"});
				filter();	
			//$('#S_TAHUN').load(base_url+'prosedur/getTahunlifting_kkks/');
			//$('#dg').datagrid('enableFilter'); 			
		});
	
		// aksi
		actionbutton = function(value, row, index){
			var col;
			col = '<a href="#" onclick="editData(\''+row.ID_KPS+'\',\''+row.TAHUN+'\',\''+row.BULAN+'\');" class="easyui-linkbutton" iconCls="icon-edit" plain="false">Lihat</a>';
			//col += '&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" onclick="deleteData(\''+row.ID+'\',\''+row.NAMA_KPS+'\',\''+row.TAHUN+'\',\''+row.BULAN+'\',\''+row.TANGGAL+'\');" class="easyui-linkbutton" iconCls="icon-edit" plain="false">Delete</a>';
			return col;
		}
		
		//gabung bulan dan tahun
		BulanTahun = function(value, row, index){
			var col='';
			col = BulandanTahun(row.BULAN) + ' ' + row.TAHUN;
			return col;
		}
	
		// onchange
		$('#S_TAHUN').change(function(){
			//$('#S_TAHUN').load(base_url+'prosedur/OptionTahunlifting_kkks/'+$('#S_TAHUN').val());
			filter();
		});
		
		// filter
		filter = function(){
			$('#dg').datagrid('load',{
				tahun : $('#S_TAHUN').val(),
			});
			//$('#dg').datagrid('enableFilter');
		}
		
		//# Tombol Bawah
		$(function(){
			var pager = $('#dg').datagrid().datagrid('getPager');	// get the pager of datagrid
			pager.pagination({
				buttons:[
					{
						iconCls:'icon-add',
						text:'Tambah Data',
						handler:function(){
							newData();
						}
					}/* ,
					{
						iconCls:'icon-print',
						text:'Export PDF',
						handler:function(){
							window.open('<?=base_url().'nominasi/pdf'?>');
						}
					} */
				]
			});			
		});
	
	});
</script>
<table id="dg" title="Data lifting_kkks" data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:20,
			fit:true,
			toolbar:'#toolbar',
			">
	<thead>
		<tr>
			<!--th field="ck" checkbox="true"></th-->
			<!--th field="ID" sortable="true" width="100">ID</th-->
			<th field="ID_KPS" hidden="true" sortable="true" width="100">ID_KPS</th>
			<th field="TAHUN" sortable="true" width="100">Tahun</th>
			<!--th field="tgl" sortable="true" width="100" formatter="BulanTahun" >Bulan/Tahun</th-->
			<!--th field="BULAN" sortable="true" width="100" formatter="BulandanTahun">Bulan</th-->
			<th field="BLN" sortable="true" width="100">Bulan</th>
			<th field="NAMA_KPS" sortable="true" width="250" >Nama KKKS</th>
			<!--th field="TANGGAL" sortable="true" width="110" formatter="FormatNamaBulan">Tanggal Nominasi</th-->
			
			<!--th data-options="field:'NOMINASI',width:50,  
      formatter:function(value, row){
      //row.NOMINASI
      return accounting.formatMoney(row.NOMINASI);
}">Nominasi</th-->
			<!--th field="DESCRIPTION" sortable="true" width="200">Deskripsi</th-->
			<th field="action" align="center" formatter="actionbutton" width="130">Aksi</th>
		</tr>
	</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
	<span>Pencarian</span>
		<input id="nama" style="line-height:26px;border:1px solid #ccc">
		
		<a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()" iconCls="icon-search">Cari</a>
	<div style="margin-bottom:5px">
		
	</div>
	<!--div>
		<table width="700" border="0">
		  <tr>
			<td>TAHUN</td>
			<td>: 
				<select id="S_TAHUN" name="S_TAHUN" style="width:290px;">
					<?=$this->prosedur_model->OptionNamaKKKS();?>
				</select>
			</td>
		  </tr>
		</table>
	</div-->
</div>
